﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FittyWars.MathUtil;

namespace FittyWars.BordUtils
{
    class Shape : Creature
    {
        public Random rand;
        public Shape(int seed)
            : base()
        {
            rand = new Random(seed);
            GameElement = GameElement.Shape;
            Center = new Vector(
                0.8f * ((float)rand.NextDouble() - 0.5f),
                0.8f * ((float)rand.NextDouble() - 0.5f)
               );
            BodyParts = new List<Polygon>();
            BodyParts.Add(MathHelper.CreateRandomConvexedPoly(3 + rand.Next(4), 0.1f + 0.1f * (float)rand.NextDouble()));
            Speed = 0.01f + (float)rand.NextDouble() * 0.03f;
            maxTime = 30 + rand.Next(30);
        }

        public Shape(int seed, Polygon p, Vector v)
            : base()
        {
            rand = new Random(seed);
            GameElement = GameElement.Shape;
            Center = v;
            BodyParts = new List<Polygon>{p};
            Speed = 0;
            maxTime = 30 + rand.Next(40);
        }

        private int times;
        private int maxTime;
        public override void Think(List<Element> nearElements)
        {
            
            if (times == 0)
            {
                Direction = (float)(2 * Math.PI * rand.NextDouble());
                times = maxTime;
            }
            else
            {
                times--;
            }
           
            /*
            foreach (Element elem in nearElements)
            {
                if (elem.GetGameElement() == GameManager.GameElement.Duck)
                {
                    double dx = Posx - elem.Posx;
                    double dy = Posy - elem.Posy;
                    Direction = Math.Atan(dy / dx);
                    if (dx > 0 ) Direction += Math.PI;
                    return;
                }
            }
            */
        }
    }
}
